<template>
    <!--
        字体选择器
        body-class="modalStyle" 表示样式
        size="lg" 表示模态窗口大小 xl,lg,sm,full
        hide-footer 表示隐藏底部按钮
        hide-header 表示隐藏头部内容
        no-close-on-backdrop 表示鼠标点击背景不可关闭
        hide-header-close 表示隐藏头部关闭按钮
        centered 居中
        ok-title=“确定” 
        cancel-title=取消
        @ok="handleOk" 
        @cancel="handleCancel"
        scrollable 滚动条
        hide-backdrop 隐藏背景
        wrapClassName="ant-modal-cust-warp" 
        style="top:5%;height: 85%;overflow-y: hidden" 样式
    -->
    <b-modal ref="my-modal" title="字体选择器" size="lg" id="tableIconBody" scrollable no-close-on-backdrop>
        <div class="d-block text-center">            
            <div class="card-body">
                <div class="form-group form-group2 m-form__group row" v-if="dataList.length === 0">
                    暂无数据
                </div>
                
                <div class="form-group form-group2 m-form__group row" v-for="(item, key) in dataList"
                    @click="doSelect(item, key)" :key="item.index">
                    <div class="col-md-2 d-flex align-items-stretch">
                        <div class="d-flex flex-grow-1 align-items-center bg-hover-light p-4 rounded">
                            <div class="mr-4 flex-shrink-0 text-center" style="width: 40px;">
                                <i class="icon-xl " :class="item.icon"></i>
                            </div>
                            <div class="text-muted">{{ item.icon }}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <template slot="modal-footer">
            <!--自定义按钮-->
            <div class="form-group m-form__group row">
                <label class="col-form-label">分类:</label>
                <div class="col-lg-2">
                    <el-select maxlength="20" v-model="searchForm.categories" placeholder="请选择">
                        <el-option v-for="item in [{ value: 'Fontawesome5', label: 'Fontawesome 5' },
                        { value: 'Flaticon', label: 'Flaticon' },
                        { value: 'Socicons', label: 'Socicons' },
                        { value: 'Lineawesome', label: 'Lineawesome' }]" :key="item.value" :label="item.label"
                            :value="item.value">
                        </el-option>
                    </el-select>
                </div>
                <label class="col-form-label">名称:</label>
                <div class="col-lg-2">
                    <input type="text" class="form-control" v-model="searchForm.name" placeholder="请输入">
                </div>
                <label class="col-form-label">字体:</label>
                <div class="col-lg-2">
                    <input type="text" class="form-control" v-model="searchForm.icon" placeholder="请输入">
                </div>                
                <b-button :pressed="false" variant="btn btn-primary font-weight-bold mr-2" @click="search()">
                    <span><i class="fa fa-search"></i><span>查询</span></span></b-button>
                <b-button :pressed="false" variant="btn btn-light font-weight-bold mr-2" @click="resetAll()">
                    <span><span>清空条件</span></span></b-button>
                <!-- <button type="button" class="btn btn-light-danger font-weight-bold mr-2" block @click="hideModal">
                    <i class="icon-xl fa fa-times"></i>关闭窗体
                </button>  -->
            </div>           
            <!-- <button type="button" class="btn btn-light-success font-weight-bold mr-2" @click="doSelect">
                <i class="icon-xl fas fa-save"></i> 确定
            </button> -->
        </template>
    </b-modal>
</template>
<script>
import apiUtil from "@/core/util/apiUtil.js";
import { handleNotify, handleAlert, handleConfirm, showWating, closeWating } from "@/core/util/jehcUtil.js";
export default {
    data() {
        return {
            searchForm: { name: "", icon: "", categories: "Fontawesome5", },
            dataList: [],
        }
    },
    mounted() {
    },
    methods: {
        showModal() {
            this.$refs['my-modal'].show();
            this.search();
        },
        hideModal() {
            this.$refs['my-modal'].hide()
        },
        toggleModal() {
            this.$refs['my-modal'].toggle('#toggle-btn')
        },
        doSelect(data) {
            this.$emit("change", data);//组件传值，即向父级模态框中传递值，采用change方式
            this.$refs['my-modal'].hide();
        },
        search() {
            this.getIconList();
        },
        resetAll() {
            Object.assign(this.$data.searchForm, this.$options.data().searchForm);
            this.search();
        },
        getIconList() {
            showWating({ renderBody: "tableIconBody" });
            apiUtil.query(process.env.VUE_APP_SYS_API + "/icon/query/list", this.searchForm).then(({ data }) => {
                this.dataList = data.data;
            });
        },
    }
}
</script>
<style scoped>
.form-group2 {
    width: 25%;
    display: inline-block;
    vertical-align: top;
    margin: 0;
}

.form-group2 .text-muted {
    white-space: pre-wrap;
    min-width: 70px;
    text-align: left;
}
</style>